import pickle

# 定义一个恶意函数
malicious_func = """  
# import os
# os.system('rm -rf /')   

with open('example.txt', 'w') as file: 
    file.write('Hello, World!')  
"""

# 生成将恶意代码文件
with open('data/malicious.pkl', 'wb') as file:
    pickle.dump(malicious_func, file)

# 从文件中加载并反序列化
with open('data/malicious.pkl', 'rb') as file:
    loaded_person = pickle.load(file)

# 执行pickle对象中的恶意函数
exec(loaded_person)



import pickle
import os

# 定义一个恶意函数
malicious_func = """  
with open('example.txt', 'w') as file: 
    file.write('Hello, World!')  
"""

# 将恶意函数打包为pickle对象
malicious_data = pickle.dumps(malicious_func)

# 执行pickle对象中的恶意函数
exec(pickle.loads(malicious_data))

